<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/jquery2.1.4.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<html>
    <head>
        <title>创建</title>
         <script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>" ></script>
         <link rel="stylesheet" type="text/css" media="screen" href="${contextPath}/resources/common/css/errorform.css" />
        <script language="javascript">
    $(document).ready(function() {
    jQuery("#form1").validate({
            rules:  {
             name: {
                required: true,
                minlength: 2
            }
        },
        messages: {
        	name: {
                required: "请输入名称",
                minlength: "最少要输入2个字"
            }
        }
    });
    
  	 //binding Submit
	 $("#Submit").click(function(){
	 if($("#form1").valid()){
	 var formData = $("#form1").serialize();
	   $.ajax({
       type: 'post', // 提交方式 get/post
       url:  "${contextPath}/admin/projectModule/batchSave", // 需要提交的 url
       data: formData,
       dataType : 'json', 
       error: function(jqXHR, textStatus, errorThrown) {
	 		 alert("保存失败" + textStatus);
		},
       success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
           // 此处可对 data 作相关处理
           if("success" == data){
             layer.msg("保存成功");
             closeDialog();
           }else{
          		layer.msg("保存失败");
           }
         
       }
   });
   return false; // 阻止表单自动提交事件
	};
	});
    
 
		//斑马条纹
     	 $("#col1 tr:nth-child(even)").addClass("even");
		
});
    
	function closeDialog(){
		var index = parent.layer.getFrameIndex("updateProjectModule"); //先得到当前iframe层的索引
		parent.layer.close(index); //再执行关闭   
		if(parent.sendData){
			parent.sendData();//异步
		}else{
			parent.location.reload();
		}
	}
</script>
</head>
    <body>
        <form action="<ls:url address='/admin/projectModule/batchSave'/>" method="post" id="form1">
            <input id="id" name="id" value="${projectModule.id}" type="hidden">
            <input id="projectId" name="projectId" value="${projectId}" type="hidden">
            <div align="center">
            <table border="0" align="center" class="${tableclass}" id="col1">
                <thead>
                    <tr class="sortable">
                        <th colspan="3">
                            <div align="center">
                                	创建项目模块
                            </div>
                        </th>
                    </tr>
                </thead>


        <c:forEach items="${projectModules}"  var="projectModule" varStatus="status">
            <tr>
                <td>${status.index +1}</td>
                <td>
                    <div align="center">名字<font color="ff0000">*</font></div>
                </td>
                <td>
                    <input type="text" name="name" id="name" value="${projectModule.name}" />
                </td>
            </tr>
        </c:forEach>




                <%
                    Integer count = (Integer)request.getAttribute("count");
                    Integer end;
                    if(count < 10){ //一个页面建议最多只有12个
                        end = 10;
                    }else{
                        end = count + 4; //每次多4个
                    }
                    for (int i = count; i < end; i++) {
                %>
                <tr>
                    <td><%=i + 1%></td>
                    <td>
                        <div align="center">名字<font color="ff0000">*</font></div>
                    </td>
                    <td>
                        <input type="text" name="name" id="name" value="${projectModule.name}" />
                    </td>
                </tr>
                <% } %>

         <tr>
              <td colspan="3">
                        <div align="center">
                            <input type="button" name="Submit" id="Submit"  value="提交" />
                            <input type="button" value="关闭" onclick="javascript:closeDialog()" />
                        </div>
               </td>
            </tr>
            </table>
              备注： 模块名字不能同名且不能为空，置空提交则会删除该记录
           </div>
        </form>
    </body>
</html>

